﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Objects;

namespace Northwind.NET.EDM.FE.WinForms.Controls
{
    public partial class CustomersPhoneListUserControl : BaseUserControl
    {
        public CustomersPhoneListUserControl()
        {
            InitializeComponent();
        }

        public override string FormCaption { get { return Settings.Resources.CustomersPhoneListFormCaption; } }
        public override dynamic GetEntitySet(ObjectContext context)
        {
            return context.CreateObjectSet<Model.Customer>();
        }

        public override BindingSource UserControlBindingSource { get { return customerBindingSource; } }

        private void letterbutton_Click(object sender, EventArgs e)
        {
            Button button = (Button)sender;

            string filter = button.Tag.ToString();
            if (filter != "*")
            {
                var result = from p in _context.Customer
                             where p.Name.StartsWith(filter)
                             select p;
                customerBindingSource.DataSource = result;
            }
            else
            {
                customerBindingSource.DataSource = _context.CreateObjectSet<Model.Customer>();
            }
        }

    }
}

